export function generateDateArray(daysAhead) {
	const currentDate = new Date();
	const dateArray = [];

	for (let i = 0; i <= daysAhead; i++) {
		const futureDate = new Date(currentDate);
		futureDate.setDate(currentDate.getDate() + i); // Add days to the current date

		const month = futureDate.getMonth() + 1; // Month is 0-indexed in JavaScript dates
		let day = futureDate.getDate();
		const weekday = getWeekday(futureDate.getDay()); // Get the weekday name
		if(day<=9){
			day = '0'+day
		}
		dateArray.push({
			date: `${month < 10 ? '0' + month : month}-${day}`,
			weekday: weekday
		});
	}

	return dateArray;
}

export function getWeekday(dayNumber) {
	const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
	return weekdays[dayNumber];
}


function parseDateString(dateString) {
    const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    const days = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'];
    
    const monthStr = dateString.split('-')[0];
    const dayStr = dateString.split('-')[1];
    
    const monthIndex = months.indexOf(monthStr);
    const dayIndex = days.indexOf(dayStr) + 1;
    if (monthIndex !== -1 && dayIndex !== -1) {
        const year = new Date().getFullYear(); // 假设年份为当前年份
        return new Date(year, monthIndex, dayIndex);
    } else {
        throw new Error('Invalid date string');
    }
}

export function generateHalfHourlyTimeArrayWithStatus(dateString) {
	const START_TIME = 21;
	const END_TIME = 6;
	
	const currentDate = new Date();
	const targetDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
	// const inputDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), dateString);
	const inputDate = parseDateString(dateString)
	const timeArray = [];
	for (let hour = 0; hour < 24; hour++) {
		timeArray.push({
			time: `${hour.toString().padStart(2, '0')}:00`,
			isPast: (hour * 60 + 0) < (currentDate.getHours() * 60 + currentDate.getMinutes()),
			isNight: (hour >= START_TIME || hour < END_TIME),
			isToday: targetDate.getTime() === inputDate.getTime()
		});
		timeArray.push({
			time: `${hour.toString().padStart(2, '0')}:30`,
			isPast: (hour * 60 + 30) < (currentDate.getHours() * 60 + currentDate.getMinutes()),
			isNight: (hour >= START_TIME || hour < END_TIME),
			isToday: targetDate.getTime() === inputDate.getTime()
		});
	}
	// Remove the last ":30" entry since it should be the next day's 00:00
	timeArray.pop();

	return timeArray.map(item => ({
		time: item.time,
		status: (() => {
			if (!item.isToday) {
				if (item.isNight) {
					return "夜间费"
				}
			};
			let status = '';
			if (item.isPast) status += '约满 ';
			else if (item.isNight && item.isToday) status += '夜间费';
			return status.trim();
		})(),
		isNight: item.isNight,
		isToday: item.isToday
	}));
}